home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Networking / MacTCP / MPing 1.1 / Sources / MPingDlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-30  |  10.6 KB  |  433 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #    MPing 1.1 - MacTCP Ping Tool
  3. #
  4. #    Copyright © Apple Computer, Inc. 1990-1991
  5. #    All rights reserved.
  6. #
  7. #    Versions:    
  8. #                1.1        September 25, 1991.
  9. #
  10. #    File:
  11. #                MPing.c
  12. #
  13. #    Components:
  14. #                AddressXlation.h
  15. #                MacTCPCommonTypes.h
  16. #                Makefile
  17. #                MiscIPPB.h
  18. #                MPing.c
  19. #                MPing.h
  20. #                MPing.r
  21. #                MPingDlg.c
  22. #                MPingExtern.h
  23. #                MPingGlobals.h
  24. #                MPingIcmp.c
  25. #                MPingWindow.c
  26. #                resolver.c
  27. ------------------------------------------------------------------------------*/
  28.  
  29. #include <values.h>
  30. #include <types.h>
  31. #include <quickdraw.h>
  32. #include <fonts.h>
  33. #include <events.h>
  34. #include <controls.h>
  35. #include <windows.h>
  36. #include <menus.h>
  37. #include <textedit.h>
  38. #include <dialogs.h>
  39. #include <desk.h>
  40. #include <scrap.h>
  41. #include <toolutils.h>
  42. #include <memory.h>
  43. #include <segload.h>
  44. #include <files.h>
  45. #include <osutils.h>
  46. #include <osevents.h>
  47. #include <diskinit.h>
  48. #include <packages.h>
  49. #include <traps.h>
  50. #include <strings.h>
  51. #include <Errors.h>
  52. #include <Devices.h>
  53. #include <String.h>
  54. #include <StdLib.h>
  55. #include <StdIO.h>
  56.  
  57. #include "MacTCPCommonTypes.h"
  58. #include "MPing.h"            /* bring in all the #defines for MPing */
  59. #include "MPingGlobals.h"    /* bring in some structure definitions for MPing */
  60. #include "MPingExtern.h"        /* all extern variables */
  61.  
  62. extern void Terminate(void);
  63. extern void DrawOnScreen(void);
  64. void DoInitDialog(DialogPtr ldialog);
  65. void DoDialogItem(DialogPtr ldialog, short itemHit);
  66.  
  67. void DoPingGo(DialogPtr ldialog, Handle itHandle);
  68. void DoPingStop(DialogPtr ldialog, Handle itHandle);
  69. void DoQuit(void);
  70. void DoHostAddrEdit(Handle itHandle);
  71. void DoSendTextRadio(DialogPtr ldialog, Handle itHandle);
  72. void DoSendTextEdit(Handle itHandle);
  73. void DoSendPatternRadio(DialogPtr ldialog, Handle itHandle);
  74. void DoSendPatternEdit(Handle itHandle);
  75. void DoPacketSizeEdit(Handle itHandle);
  76. void DoQuietRadio(DialogPtr ldialog, Handle itHandle);
  77. void DoVerboseRadio(DialogPtr ldialog, Handle itHandle);
  78. void DoNoOfPktsCheck(DialogPtr ldialog, Handle itHandle);
  79. void DoNoOfPktsEdit(Handle itHandle);
  80. void DoWaitSecEdit(Handle itHandle);
  81. void DoSendASyncCheck(Handle itHandle);
  82. extern OSErr IcmpPingSetup(void);
  83. extern void DrawErrorMessageOnScreen(short errMsg);
  84.  
  85. Str255        zHostAddr, zData, zPattern, zSize, zCount, zWait;
  86.  
  87.  
  88. void DoDialogItem(ldialog, itemHit)
  89. DialogPtr ldialog;
  90. short itemHit;
  91. {
  92.     short        titType;
  93.     Handle        titHandle;
  94.     Rect        titDispRect;
  95.     short        uFlag=1;
  96.  
  97.     GetDItem(ldialog, itemHit, &titType, &titHandle, &titDispRect);
  98.     switch (itemHit) {
  99.         case PINGGO_BUTTON:
  100.                 if (!gRunning)
  101.                     DoPingGo(ldialog, titHandle);
  102.                 break;
  103.         case PINGSTOP_BUTTON:
  104.                 if (gRunning)
  105.                     DoPingStop(ldialog, titHandle);
  106.                 break;
  107.         case QUIT_BUTTON:
  108.                 DoQuit();
  109.                 if (!gRunning)
  110.                     break;
  111.         case HOSTADDR_EDIT:
  112.                 if (!gRunning)
  113.                     DoHostAddrEdit(titHandle);
  114.                 break;
  115.         case SENDTEXT_RADIO:
  116.                 if (!gRunning)
  117.                     DoSendTextRadio(ldialog, titHandle);
  118.                 break;
  119.         case SENDTEXT_EDIT:
  120.                 if (!gRunning)
  121.                     DoSendTextEdit(titHandle);
  122.                 break;
  123.         case SENDPATTERN_RADIO:
  124.                 if (!gRunning)
  125.                     DoSendPatternRadio(ldialog, titHandle);
  126.                 break;
  127.         case SENDPATTERN_EDIT:
  128.                 if (!gRunning)
  129.                     DoSendPatternEdit(titHandle);
  130.                 break;
  131.         case PACKETSIZE_EDIT:
  132.                 if (!gRunning)
  133.                     DoPacketSizeEdit(titHandle);
  134.                 break;
  135.         case QUIET_RADIO:
  136.                 if (!gRunning)
  137.                     DoQuietRadio(ldialog, titHandle);
  138.                 break;
  139.         case VERBOSE_RADIO:
  140.                 if (!gRunning)
  141.                     DoVerboseRadio(ldialog, titHandle);
  142.                 break;
  143.         case NOOFPKTS_CHECK:
  144.                 if (!gRunning)
  145.                     DoNoOfPktsCheck(ldialog, titHandle);
  146.                 break;
  147.         case NOOFPKTS_EDIT:
  148.                 if (!gRunning)
  149.                     DoNoOfPktsEdit(titHandle);
  150.                 break;
  151.         case WAITSEC_EDIT:
  152.                 if (!gRunning)
  153.                     DoWaitSecEdit(titHandle);
  154.                 break;
  155.         default:
  156.                 break;
  157.     }
  158. }
  159.  
  160. void DoHostAddrEdit(itHandle)
  161. Handle itHandle;
  162. {
  163.     GetIText(itHandle,zHostAddr);
  164.     SetIText(itHandle,zHostAddr);
  165.     strcpy((char *) gHostAddress, (char *) p2cstr(zHostAddr));
  166. }
  167.  
  168. void DoSendTextRadio(ldialog, itHandle)
  169. DialogPtr ldialog;
  170. Handle itHandle;
  171. {
  172.     short        titType;
  173.     Handle        titHandle;
  174.     Rect        titDispRect;
  175.  
  176.     SetCtlValue((ControlHandle) itHandle, 1);
  177.     ShowDItem(ldialog, SENDTEXT_EDIT);
  178.     GetDItem(ldialog, SENDPATTERN_RADIO, &titType, &titHandle, &titDispRect);
  179.     SetCtlValue((ControlHandle) titHandle, 0);
  180.     HideDItem(ldialog, SENDPATTERN_EDIT);
  181.     gTextPattern = true;
  182. }
  183.  
  184. void DoSendTextEdit(itHandle)
  185. Handle itHandle;
  186. {
  187.     GetIText(itHandle,zData);
  188.     SetIText(itHandle,zData);
  189.     strcpy(gData, p2cstr(zData));
  190. }
  191.  
  192. void DoSendPatternRadio(ldialog, itHandle)
  193. DialogPtr ldialog;
  194. Handle itHandle;
  195. {
  196.     short        titType;
  197.     Handle        titHandle;
  198.     Rect        titDispRect;
  199.  
  200.     SetCtlValue((ControlHandle) itHandle, 1);
  201.     ShowDItem(ldialog, SENDPATTERN_EDIT);
  202.     GetDItem(ldialog, SENDTEXT_RADIO, &titType, &titHandle, &titDispRect);
  203.     SetCtlValue((ControlHandle) titHandle, 0);
  204.     HideDItem(ldialog, SENDTEXT_EDIT);
  205.     gTextPattern = false;
  206. }
  207.  
  208. void DoSendPatternEdit(itHandle)
  209. Handle itHandle;
  210. {
  211.     GetIText(itHandle,zPattern);
  212.     SetIText(itHandle,zPattern);
  213.     strcpy(gPattern, p2cstr(zPattern));
  214. }
  215.  
  216. void DoPacketSizeEdit(itHandle)
  217. Handle itHandle;
  218. {
  219.     GetIText(itHandle,zSize);
  220.     SetIText(itHandle,zSize);
  221.     gSize = atoi(p2cstr(zSize));            
  222. }
  223.  
  224. void DoQuietRadio(ldialog, itHandle)
  225. DialogPtr ldialog;
  226. Handle itHandle;
  227. {
  228.     short        titType;
  229.     Handle        titHandle;
  230.     Rect        titDispRect;
  231.  
  232.     SetCtlValue((ControlHandle) itHandle, 1);
  233.     GetDItem(ldialog, VERBOSE_RADIO, &titType, &titHandle, &titDispRect);
  234.     SetCtlValue((ControlHandle) titHandle, 0);
  235.     gQuietVerbose = true;
  236. }
  237.  
  238. void DoVerboseRadio(ldialog, itHandle)
  239. DialogPtr ldialog;
  240. Handle itHandle;
  241. {
  242.     short        titType;
  243.     Handle        titHandle;
  244.     Rect        titDispRect;
  245.  
  246.     SetCtlValue((ControlHandle) itHandle, 1);
  247.     GetDItem(ldialog, QUIET_RADIO, &titType, &titHandle, &titDispRect);
  248.     SetCtlValue((ControlHandle) titHandle, 0);
  249.     gQuietVerbose = false;
  250. }
  251.  
  252. void DoNoOfPktsCheck(ldialog, itHandle)
  253. DialogPtr ldialog;
  254. Handle itHandle;
  255. {
  256.     short        uFlag=1;
  257.  
  258.     uFlag = GetCtlValue((ControlHandle) itHandle);
  259.     if (uFlag == 1) {
  260.         uFlag = 0;
  261.         SetCtlValue((ControlHandle) itHandle, uFlag);
  262.         HideDItem(ldialog, NOOFPKTS_EDIT);
  263.         gFixedNoOfPkts = false;
  264.     }
  265.     else {
  266.         uFlag = 1;
  267.         SetCtlValue((ControlHandle) itHandle, uFlag);
  268.         ShowDItem(ldialog, NOOFPKTS_EDIT);
  269.         gFixedNoOfPkts = true;
  270.     }
  271. }
  272.  
  273. void DoNoOfPktsEdit(itHandle)
  274. Handle itHandle;
  275. {
  276.     GetIText(itHandle,zCount);
  277.     SetIText(itHandle,zCount);
  278.     gCount = atoi(p2cstr(zCount));            
  279. }
  280.  
  281. void DoWaitSecEdit(itHandle)
  282. Handle itHandle;
  283. {
  284.     GetIText(itHandle,zWait);
  285.     SetIText(itHandle,zWait);
  286.     gWait = atoi(p2cstr(zWait));            
  287. }
  288.  
  289. void DoPingGo(ldialog, itHandle)
  290. DialogPtr ldialog;
  291. Handle itHandle;
  292. {
  293.     short        titType;
  294.     Handle        titHandle;
  295.     Rect        titDispRect;
  296.  
  297.     if (IcmpPingSetup() == noErr) {
  298.         gRunning = true;
  299.         gSessionComplete = false;
  300.         HideControl((ControlHandle) itHandle);
  301.         GetDItem(ldialog, PINGSTOP_BUTTON, &titType, &titHandle, &titDispRect);
  302.         ShowControl((ControlHandle) titHandle);
  303.         DrawHostInfoOnScreen();
  304.     }
  305.     else {
  306.         SysBeep(10);
  307.         DrawHostInfoOnScreen();
  308.         DrawErrorMessageOnScreen(sHostNotResp);
  309.     }
  310. }
  311.  
  312. void DoPingStop(ldialog, itHandle)
  313. DialogPtr ldialog;
  314. Handle itHandle;
  315. {
  316.     short        titType;
  317.     Handle        titHandle;
  318.     Rect        titDispRect;
  319.  
  320.     gRunning = false;
  321.     gSessionComplete = true;
  322.     HideControl((ControlHandle) itHandle);
  323.     GetDItem(ldialog, PINGGO_BUTTON, &titType, &titHandle, &titDispRect);
  324.     ShowControl((ControlHandle) titHandle);
  325.  
  326.     gIcmpStat.pktLoss = (gIcmpStat.totPktOut == 0 ? 0 :
  327.         ((100.0 * (double)(gIcmpStat.totPktOut - gIcmpStat.totPktIn))/(double)gIcmpStat.totPktOut));
  328.     gIcmpStat.avgTime = (gIcmpStat.totPktIn == 0 ? 0 : gIcmpStat.totTime/(unsigned long) gIcmpStat.totPktIn);
  329.  
  330.     DrawOnScreen();
  331. }
  332.  
  333. void DoQuit(void)
  334. {
  335.     Terminate();
  336. }
  337.  
  338. void DoInitDialog(ldialog)
  339. DialogPtr ldialog;
  340. {
  341.     short        titType;
  342.     Handle        titHandle;
  343.     Rect        titDispRect;
  344.  
  345.     gHostAddress[0] = '\0';
  346.     gData[0] = '\0';
  347.     gPattern[0] = '\0';
  348.     gSize=DEFAULT_ICMP_SIZE;
  349.     gCount=DEFAULT_PKT_COUNT;
  350.     gWait=ICMP_TIME_DELAY;
  351.     gTextPattern=true;
  352.     gQuietVerbose=true;
  353.     gFixedNoOfPkts=true;
  354.  
  355.     strcpy((char *) zHostAddr, gHostAddress);
  356.     c2pstr(zHostAddr);
  357.     strcpy((char *) zData, gData);
  358.     c2pstr(zData);
  359.     strcpy((char *) zPattern, gPattern);
  360.     c2pstr(zPattern);
  361.     NumToString((long) gSize, zSize);
  362.     NumToString((long) gCount, zCount);
  363.     NumToString((long) gWait, zWait);
  364.  
  365.     GetDItem(ldialog, HOSTADDR_EDIT, &titType, &titHandle, &titDispRect);
  366.     SetIText(titHandle, zHostAddr);
  367.  
  368.     if (gTextPattern == true) {
  369.         GetDItem(ldialog, SENDTEXT_RADIO, &titType, &titHandle, &titDispRect);
  370.         SetCtlValue((ControlHandle) titHandle, 1);
  371.         GetDItem(ldialog, SENDTEXT_EDIT, &titType, &titHandle, &titDispRect);
  372.         SetIText(titHandle, zData);
  373.  
  374.         GetDItem(ldialog, SENDPATTERN_RADIO, &titType, &titHandle, &titDispRect);
  375.         SetCtlValue((ControlHandle) titHandle, 0);
  376.         HideDItem(ldialog, SENDPATTERN_EDIT);
  377.     }
  378.     else {
  379.         GetDItem(ldialog, SENDTEXT_RADIO, &titType, &titHandle, &titDispRect);
  380.         SetCtlValue((ControlHandle) titHandle, 0);
  381.         HideDItem(ldialog, SENDTEXT_EDIT);
  382.  
  383.         GetDItem(ldialog, SENDPATTERN_RADIO, &titType, &titHandle, &titDispRect);
  384.         SetCtlValue((ControlHandle) titHandle, 1);
  385.         GetDItem(ldialog, SENDPATTERN_EDIT, &titType, &titHandle, &titDispRect);
  386.         SetIText(titHandle, zPattern);
  387.     }
  388.  
  389.     GetDItem(ldialog, PACKETSIZE_EDIT, &titType, &titHandle, &titDispRect);
  390.     SetIText(titHandle, zSize);
  391.  
  392.     if (gQuietVerbose == true) {
  393.         GetDItem(ldialog, QUIET_RADIO, &titType, &titHandle, &titDispRect);
  394.         SetCtlValue((ControlHandle) titHandle, 1);
  395.         GetDItem(ldialog, VERBOSE_RADIO, &titType, &titHandle, &titDispRect);
  396.         SetCtlValue((ControlHandle) titHandle, 0);
  397.     }
  398.     else {
  399.         GetDItem(ldialog, QUIET_RADIO, &titType, &titHandle, &titDispRect);
  400.         SetCtlValue((ControlHandle) titHandle, 0);
  401.         GetDItem(ldialog, VERBOSE_RADIO, &titType, &titHandle, &titDispRect);
  402.         SetCtlValue((ControlHandle) titHandle, 1);
  403.     }
  404.  
  405.     if (gFixedNoOfPkts == true) {
  406.         GetDItem(ldialog, NOOFPKTS_CHECK, &titType, &titHandle, &titDispRect);
  407.         SetCtlValue((ControlHandle) titHandle, 1);
  408.         GetDItem(ldialog, NOOFPKTS_EDIT, &titType, &titHandle, &titDispRect);
  409.         SetIText(titHandle, zCount);
  410.     }
  411.     else {
  412.         GetDItem(ldialog, NOOFPKTS_CHECK, &titType, &titHandle, &titDispRect);
  413.         SetCtlValue((ControlHandle) titHandle, 0);
  414.         HideDItem(ldialog, NOOFPKTS_EDIT);
  415.     }
  416.  
  417.     GetDItem(ldialog, WAITSEC_EDIT, &titType, &titHandle, &titDispRect);
  418.      SetIText(titHandle, zWait);
  419.  
  420.     if (gRunning == false) {
  421.         GetDItem(ldialog, PINGSTOP_BUTTON, &titType, &titHandle, &titDispRect);
  422.         HideControl((ControlHandle) titHandle);
  423.         GetDItem(ldialog, PINGGO_BUTTON, &titType, &titHandle, &titDispRect);
  424.         ShowControl((ControlHandle) titHandle);
  425.     }
  426.     else {
  427.         GetDItem(ldialog, PINGGO_BUTTON, &titType, &titHandle, &titDispRect);
  428.         HideControl((ControlHandle) titHandle);
  429.         GetDItem(ldialog, PINGSTOP_BUTTON, &titType, &titHandle, &titDispRect);
  430.         ShowControl((ControlHandle) titHandle);
  431.     }
  432. }
  433.